package com.xbts.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnCloudMarketSku;
import com.xbts.system.service.ICnCloudMarketSkuService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 云市场规格Controller
 * @author xbts
 * @date 2023-10-16
 */
@Api("云市场规格")
@RestController
@RequestMapping("/system/market/sku")
public class CnCloudMarketSkuController extends BaseController {

    @Autowired
    private ICnCloudMarketSkuService cnCloudMarketSkuService;

    /**
     * 查询云市场规格列表
     */
    @ApiOperation("查询云市场规格列表")
    @PreAuthorize("@ss.hasPermi('system:market:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnCloudMarketSku cnCloudMarketSku) {
        startPage(cnCloudMarketSku);
        List<CnCloudMarketSku> list = cnCloudMarketSkuService.selectCnCloudMarketSkuList(cnCloudMarketSku);
        return getDataTable(list);
    }

    /**
     * 导出云市场规格列表
     */
    @ApiOperation("导出云市场规格列表")
    @PreAuthorize("@ss.hasPermi('system:market:export')")
    @Log(title = "云市场规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnCloudMarketSku cnCloudMarketSku) {
        List<CnCloudMarketSku> list = cnCloudMarketSkuService.selectCnCloudMarketSkuList(cnCloudMarketSku);
        ExcelUtil<CnCloudMarketSku> util = new ExcelUtil<CnCloudMarketSku>(CnCloudMarketSku.class);
        util.exportExcel(response, list, "云市场规格数据");
    }

    /**
     * 获取云市场规格详细信息
     */
    @ApiOperation("获取云市场规格详细信息")
    @ApiImplicitParam(name = "marketSkuId", value = "云市场规格ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:market:query')")
    @GetMapping(value = "/{marketSkuId}")
    public AjaxResult getInfo(@PathVariable("marketSkuId") String marketSkuId) {
        return success(cnCloudMarketSkuService.selectCnCloudMarketSkuById(marketSkuId));
    }

    /**
     * 新增云市场规格
     */
    @ApiOperation("新增云市场规格")
    @PreAuthorize("@ss.hasPermi('system:market:add')")
    @Log(title = "云市场规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnCloudMarketSku cnCloudMarketSku) {
        return toAjax(cnCloudMarketSkuService.insertCnCloudMarketSku(cnCloudMarketSku));
    }

    /**
     * 修改云市场规格
     */
    @ApiOperation("修改云市场规格")
    @PreAuthorize("@ss.hasPermi('system:market:edit')")
    @Log(title = "云市场规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnCloudMarketSku cnCloudMarketSku) {
        return toAjax(cnCloudMarketSkuService.updateCnCloudMarketSku(cnCloudMarketSku));
    }

    /**
     * 删除云市场规格
     */
    @ApiOperation("删除云市场规格")
    @ApiImplicitParam(name = "marketSkuIds", value = "云市场规格ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:market:remove')")
    @Log(title = "云市场规格", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> marketSkuIds) {
        return toAjax(cnCloudMarketSkuService.deleteCnCloudMarketSkuByIds(marketSkuIds));
    }
}
